<template>
  <Header>
    <div v-if="!isPersonPage" slot="hidden" class="home-header-container">
      <h1>易动</h1>
      <ul class="head-list">
        <li
          v-for="(item, index) in headItems"
          :key="index"
          :class="{ active: isClickIndex === index }"
          @click="itemClick(index)"
        >
          {{ item }}
        </li>
      </ul>
      <search-box class="search-box" width="20.5rem"></search-box>
    </div>
    <div
      v-else
      slot="hidden"
      class="home-header-container home-header-container-person"
    >
      <ul class="head-list-person">
        <a href="" class="img">
          <img :src="avatarImg" alt="" />
        </a>
        <button
          v-for="(item, index) in personHeadItems"
          :key="index"
          :class="{ 'person-active': isClickIndex === index }"
          @click="itemClick(index)"
        >
          {{ item }} {{ listsCount[index] }}
        </button>
      </ul>
      <button class="edit">编辑个人资料</button>
    </div>
  </Header>
</template>

<script>
import Header from "@/components/header/Header";
import SearchBox from "@/components/header/SearchBox";
export default {
  name: "HomeHeader",
  components: {
    Header,
    SearchBox,
  },
  props: ["isPersonPage"],
  data() {
    return {
      isClickIndex: 0,
      headItems: ["推荐", "关注", "热榜"],
      personHeadItems: [
        "动态",
        "回答",
        "视频",
        "提问",
        "文章",
        "专栏",
        "想法",
        "收藏",
        "关注",
      ],
      avatarImg: localStorage.getItem("avatarImg"),
      listsCount: [null, 0, 0, 0, 0, 0, 0, 0, null],
    };
  },
  methods: {
    itemClick(index) {
      this.isClickIndex = index;
    },
  },
};
</script>

<style lang="scss" scoped>
.home-header-container-person {
  justify-content: space-between;
}
.home-header-container {
  position: relative;
  display: flex;
  align-items: center;
  width: 100rem;
  height: 6rem;
  margin: 0 auto;
  background: #fff;
  h1 {
    height: 100%;
    width: 6rem;
    font-size: 3rem;
    line-height: 6rem;
    color: #2d8cf0;
    font-weight: bold;
  }
  .head-list {
    display: flex;
    justify-content: flex-start;
    padding-left: 1.8rem;
    li {
      line-height: 6rem;
      margin: 0 2.2rem;
      cursor: pointer;
      &:not(.active):hover {
        color: #175199;
      }
    }
  }
  .head-list-person {
    display: flex;
    align-items: center;
    .img {
      width: 4rem;
      height: 4rem;
      img {
        width: 100%;
        height: 100%;
      }
    }
    button {
      line-height: 6rem;
      margin: 0 1.7rem;
      cursor: pointer;
      &:not(.active):hover {
        color: #175199;
      }
    }
  }
  .search-box {
    position: absolute;
    right: 0;
  }
  .active {
    color: #0084ff;
  }
  .person-active {
    position: relative;
    color: #000;
    font-weight: bold;
  }
  .person-active::after {
    content: "";
    position: absolute;
    top: 5rem;
    left: 0;
    height: 0.4rem;
    width: 3.5rem;
    background: #0084ff;
  }
  .edit {
    width: 11.8rem;
    height: 3.4rem;
    text-align: center;
    line-height: 3.4rem;
    border-radius: 0.3rem;
    color: #0084ff;
    border: 1px solid #0084ff;
  }
}
</style>